<template>
  <div
    class="myRow"
    :class="{
      leafRow: columns.every(v => !v.children || v.children.length == 0)
    }"
  >
    <div
      v-for="(item, index) in columns"
      :key="index"
      class="myCol"
      :class="{ leafCol: !item.children || item.children.length == 0 }"
      :style="{
        width: index === 0 ? parseFloat(item.width) - 1 + 'px' : item.width,
        flexShrink: item.width ? 0 : 1
      }"
    >
      <div class="headerTitle">
        {{ item.label }}
      </div>
      <TableHeaderRow
        v-if="item.children && item.children.length > 0"
        :columns="item.children"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'

export default defineComponent({
  name: 'TableHeaderRow',
  props: {
    columns: {
      type: Array,
      default: () => []
    }
  },
  setup(props) {
    const state = reactive({})

    return {
      ...toRefs(state)
    }
  }
})
</script>

<style scoped lang="scss">
.myRow {
  display: flex;
  border-top: 1px solid #000;
  width: 100%;

  &.leafRow {
    height: 100%;
  }

  .myCol {
    width: 100%;
    border-left: 1px solid #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    // flex-wrap: wrap;
    &:first-child {
      border-left: none;
    }

    &.leafCol {
      .headerTitle {
        height: 100%;
        display: flex;
        align-items: center;
      }
    }

    .headerTitle {
      padding: 6px;
    }
  }
}
</style>
